package net.zjitc.utils;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * @version 1.0
 * @autho dell
 * @date 2018/10/8
 */
public class C3p0Utils {
    private static DataSource dataSource = null;
    static {
        ComboPooledDataSource ds = new ComboPooledDataSource("shop");
        dataSource = ds;
    }

    /**
     * 返回数据源
     * @return
     */
    public static DataSource getDataSource() {
        return dataSource;
    }

    /**
     * 返回数据库连接对象
     * @return
     */
    public static Connection getConnection(){
        try {
            return dataSource.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
